package com.lanqiao.javaparkinglot.controller;

import com.lanqiao.javaparkinglot.common.CommonResult;
import com.lanqiao.javaparkinglot.entity.Driver;
import com.lanqiao.javaparkinglot.service.DriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

@RestController
@RequestMapping("/driver")
@CrossOrigin
public class DriverController {
    @Autowired
    DriverService driverService;

    //查询
    @GetMapping("/cha")
    public CommonResult findsj(Driver driver){
        List<Driver> driverList= driverService.findsj();
        return CommonResult.success("司机空闲表查询成功",driverList);
    }

    //添加
    @PostMapping("/tianjia")
    public CommonResult addsj(@RequestBody Driver driver){
       driverService.addsj(driver);
       return CommonResult.success("司机添加成功");
    }

    //修改
    @PutMapping("/xiugai")
    public CommonResult updatesj(@RequestBody Driver driver){
        driverService.updatesj(driver);
        return  CommonResult.success("司机信息修改成功");
    }

    //删除
    @DeleteMapping("/shan/{sj_eno}")
    public CommonResult deletesj(@PathVariable("sj_eno") Long sj_eno){
        driverService.deletesj(sj_eno);
        return CommonResult.success("删除数据成功");
    }


}
